<template>
	<view>
		<view>
			<button v-show="showPhoneContact" @click="addPhoneContact()">添加到通讯录</button>
			<button @click="chooseAddress()">地址管理</button>
			<button @click="chooseInvoiceTitle()">发票管理</button>
			<button @click="openSetting()">权限设置</button>
			<button type="warn" @click="loginOut()">退出登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showPhoneContact: true
			}
		},
		onShow() {
		},
		methods: {
			/* 添加手机联系人 */
			addPhoneContact(){
				uni.addPhoneContact({
					nickName: '言少钱',
					lastName: '程',
					firstName: '强',
					remark: 'JAVA工程师',
					mobilePhoneNumber: '18208222473',
					weChatNumber: '',
					success: function () {
						uni.showToast({
							title:'添加成功'
						})
					},
					fail: function () {
						uni.showToast({
							title:'添加失败'
						})
					}
				});
			},
			/* 打开设置 */
			openSetting(){
				let that = this;
				uni.openSetting({
				  success(res) {
					  console.log(res)
				    if(res.authSetting['scope.addPhoneContact']){
						that.showPhoneContact = true;
					}else{
						that.showPhoneContact = false;
					}
				  }
				});
			},
			/* 用户地址 */
			chooseAddress(){
				uni.chooseAddress({
				  success(res) {
				    console.log(res)
				  }
				})
			},
			/* 发票管理 */
			chooseInvoiceTitle(){
				uni.chooseInvoiceTitle({
				    success(res) {
				        console.log(res);
				  }
				})
			},
			/* 退出登录 */
			loginOut(){
				// 清空缓存
				uni.clearStorageSync();
				// 提示消息
				uni.showToast({
					title:'退出成功'
				})
				let timer = setTimeout(()=>{
					clearTimeout(timer);
					// 跳转到登录页面
					uni.navigateTo({
						url:'/pages/login/login'
					})
				},1000);
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>
